<?php
namespace Home\Controller;
use Think\Controller;
class NoticeController extends Controller {
    /**
     * 公告列表
     */
    public function showlists() {
        $M_category = M('notice');
        $category_rows = $M_category->select();
        $this->category_rows = $category_rows;
        $this->display();
    }
    
    /**
     * 添加公告
     */
    public function add() {
        if(IS_POST){
            $M_category = M('notice');
            $data['title'] = I('post.title');
            $data['smalltext'] = I('post.smalltext');
            $data['addtime'] = date("Y-m-d H:i:s");
            $added_row = $M_category->add($data);
            if ($added_row) {
                $this->success('添加成功', U('showlists'));
            } else {
                $this->error('添加失败');
            }
        } else {
            $this->display();
        }
    }
    /**
    * 公告详情
     */
    public function detail(){
        $id = I('get.id');
        $M_category = M('notice');
        $cate_row = $M_category->find($id);
        //print_r($cate_row);die;
        $this->cate_row = $cate_row;
        $this->display();
    }
    /**
     * 删除公告
     */
    public function del() {
        $M_notice       = M("notice");
        $id         = I("get.id");
        $del_row    = $M_notice->where(array('id'=>$id))->delete();
        if ($del_row) {
            $this->success("删除成功", U("showlists"));
        } else {
            $this->error("删除失败");
        }
    }
}